package ldh.im.fxbase.data.pojo;

import ldh.im.dto.enums.MessageType;
import ldh.im.fxbase.data.pojo.status.ImCollectContent;
import ldh.im.fxbase.data.pojo.status.ImCollectStatus;
import ldh.rpc.util.JsonUtil;

import java.util.Date;
import java.util.Objects;
import java.util.Set;

// 消息收藏
public class ImCollect {

    private Long id;
    private String userId;
    private String serverId;
    private String messageId;
    private String sessionId;
    private String content;
    private String labelIds;
    private MessageType messageType;
    private ImCollectStatus status;
    private Date createTime;
    private Date updateTime;

    private transient ImCollectContent collectContent;
    private transient Set<String> labelIdSet;

    public ImCollect() {
        createTime = new Date();
        updateTime = createTime;
        status = ImCollectStatus.enable;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public ImCollectStatus getStatus() {
        return status;
    }

    public void setStatus(ImCollectStatus status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public ImCollectContent getCollectContent() {
        if (content != null && collectContent == null) {
            collectContent = JsonUtil.toObject(content, ImCollectContent.class);
        }
        return collectContent;
    }

    public void setCollectContent(ImCollectContent collectContent) {
        this.collectContent = collectContent;
        this.content = JsonUtil.toJson(collectContent);
    }

    public String getMessageId() {
        return messageId;
    }

    public void setMessageId(String messageId) {
        this.messageId = messageId;
    }

    public String getLabelIds() {
        return labelIds;
    }

    public void setLabelIds(String labelIds) {
        this.labelIds = labelIds;
    }

    public Set<String> getLabelIdSet() {
        return labelIdSet;
    }

    public void setLabelIdSet(Set<String> labelIdSet) {
        this.labelIdSet = labelIdSet;
    }

    public String getSessionId() {
        return sessionId;
    }

    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }

    public String getServerId() {
        return serverId;
    }

    public void setServerId(String serverId) {
        this.serverId = serverId;
    }

    public MessageType getMessageType() {
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof ImCollect)) return false;
        ImCollect imCollect = (ImCollect) obj;
        if (imCollect.getId() != null && this.getId() != null) {
            return imCollect.getId().equals(this.getId());
        }
        if (imCollect.getServerId() != null && this.getServerId() != null) {
            return imCollect.getServerId().equals(this.getServerId());
        }
        return imCollect.getSessionId().equals(this.getSessionId()) &&
                imCollect.getMessageId().equals(this.getMessageId()) &&
                imCollect.getUserId().equals(this.getUserId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, sessionId, messageId);
    }
}
